package exo1;


	import java.io.*;
	import java.util.NoSuchElementException;
	import java.util.Scanner;

	public class Vehicule {
		
		
		private int id;
		private String marque;
		private String model;
		private int annee;
		private double kilometrage;
		private double prix;
		private int nb_exemplaire;
		
		public Vehicule() {
			super();//constructeur dans le quel sera construit les elements 
		
		}
		
		public Vehicule(int id,String marque, String model, int annee, double kilometrage,
				double prix, int nb_exemplaire) {
			super();
			this.id = id;
			this.marque= marque;
			this.model = model;
			this.annee = annee;
			this.kilometrage = kilometrage;
			this.prix = prix;
			this.nb_exemplaire = nb_exemplaire;
		}
		public int getId() {
			return id;
		}
		
		public String getMarque() {
			return marque;
		}
		public String getModel() {
			return model;
		}
		public int getAnnee() {
			return annee;
		}
		public double getKilometrage() {
			return kilometrage;
		}
		public double getPrix() {
			return prix;
		}
		public int getNb_exemplaire() {
			return nb_exemplaire;
		}
		public void setId(int id) {
			this.id = id;
		}
		
		public void setMarque(String marque) {
			this.marque = marque;
		}
			
		public void setModel(String model) {
			this.model = model;
		}
		public void setAnnee(int annee) {
			this.annee = annee;
		}
		public void setKilometrage(double kilometrage) {
			this.kilometrage = kilometrage;
		}
		public void setPrix(double prix) {
			this.prix = prix;
		}
		public void setNb_exemplaire(int nb_exemplaire) {
			this.nb_exemplaire = nb_exemplaire;
		}
		
		
		
		@Override
		public String toString() {
			return  id+"|"+ marque+"|"+ model+"|" +annee+"|"+ kilometrage+"|"+ prix+"|" +nb_exemplaire;
		}
		/*@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + annee;
			result = prime * result + id;
			long temp;
			temp = Double.doubleToLongBits(kilometrage);
			result = prime * result + (int) (temp ^ (temp >>> 32));
			result = prime * result + ((model == null) ? 0 : model.hashCode());
			result = prime * result + nb_exemplaire;
			temp = Double.doubleToLongBits(prix);
			result = prime * result + (int) (temp ^ (temp >>> 32));
			return result;
		}*/
		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Vehicule other = (Vehicule) obj;
			if (annee != other.annee)
				return false;
			if (id != other.id)
				return false;
			if (Double.doubleToLongBits(kilometrage) != Double
					.doubleToLongBits(other.kilometrage))
				return false;
			if (marque == null) {
				if (other.marque != null)
					return false;
			} else if (!marque.equals(other.marque))
				return false;
			if (model == null) {
				if (other.model != null)
					return false;
			} else if (!model.equals(other.model))
				return false;
			if (nb_exemplaire != other.nb_exemplaire)
				return false;
			if (Double.doubleToLongBits(prix) != Double
					.doubleToLongBits(other.prix))
				return false;
			return true;
		}


		//Je lis dans le fichier 
		//public void Lire(Scanner in){
			
		public void readData(Scanner scanner){
			//String ligne;
			while (true)
				//while ((ligne = br.readLine()) != null)
			{
				try
			    {
					String line = scanner.nextLine() ;
		            String[] tokens = line.split("\\|");
		            this.setId(Integer.parseInt(tokens[0]));
		            this.setMarque(tokens[1]);
		            this.setModel(tokens[2]);
		            this.setAnnee(Integer.parseInt(tokens[3]));
		            this.setKilometrage(Double.parseDouble(tokens[4]));
		            this.setPrix(Double.parseDouble(tokens[5]));
		            this.setNb_exemplaire(Integer.parseInt(tokens[6]));
		            System.out.println(this.toString());
			    }
			    catch (NoSuchElementException exception)
			    {
			        break;
			    }
			}		 
			
			
		}

		public void writeData(PrintWriter out){
			
				out.print("\n"+this.toString());
			}
		

}
